# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: browser.py
# Time: 17:19

from pywinauto.keyboard import send_keys
from selenium.webdriver import ActionChains
from selenium.webdriver import Chrome

from common.element.element import WebTools


class AcquireBrowser():
    def __init__(self, driver, log):
        self.__driver = driver
        self.__log = log
        self.__tools = WebTools(driver, log)

    def get_vesion(self):
        '''
        获取浏览器版本
        :return: 返回版本号
        '''
        return self.__driver.capabilities['version']

    def get_url(self):
        '''
        获取当前页面的url
        :return: 返回url
        '''
        return self.__driver.current_url

    def execute_javascript(self, srt):
        '''
        执行JavaScript语句
        :param srt: script语句
        :return:
        '''
        return self.__driver.execute_script(srt)

    def upload_files(self, *args):
        '''
        上传文件
        :param key: 文件个数
        :param args: 文件路径
        :return:
        '''
        try:
            send_keys(*args)
            send_keys('{VK_RETURN}')
        except Exception as e:
            self.__log.error("文件上传失败：{}".format(e))

    def page_source(self):
        '''
        获取网页远吗
        :return: 返源码信息
        '''
        try:
            return self.__driver.page_source
        except Exception as e:
            self.__log.error("获取源码失败：{}".format(e))




if __name__ == '__main__':
    driver = Chrome()
    driver.get("http://www.baidu.com")
    # app = AcquireBrowser(driver,logger())
    # print(app.get_vesion())
    print(driver.capabilities['version'])
